<?php

class IndexController extends Common
{
    public $linkage;
    public $member;
    public function __construct()
    {
        parent::__construct();
        $this->member = $this->model('member');
        $this->linkage = $this->model('linkage');
    }

    /**
     *  .--,       .--,
     * ( (  \.---./  ) )
     *  '.__/o   o\__.'
     *     {=  ^  =}
     *      >  -  <
     *     /       \
     *    //       \\
     *   //|   .   |\\
     *   "'\       /'"_.-~^`'-.
     *      \  _  /--'         `
     *    ___)( )(___
     *   (((__) (__)))
     */

    public function indexAction(){
        if(!get_cookie('openid')){
		    $this->oauthlogin();//微信授权跟获取
		}
        $this->view->display('wei_index');
    }

    //微信回调
    public function xoauthAction()
    {
        $code = $_GET['code'];
        $appid = $this->inwx_config['appid'];
        $secret = $this->inwx_config['appsecret'];
        /*根据code获取用户openid*/
        $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$secret&code=" . $code . "&grant_type=authorization_code";
        $abs = file_get_contents($url);
        $obj = json_decode($abs);
        $access_token = $obj->access_token;
        $openid = $obj->openid;
        /*根据code获取用户openid end*/
        set_cookie('openid', $openid, 86400);
        set_cookie('access_token', $access_token, 86400);
//        $abs_url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid."&lang=zh_CN";
//        $abs_url_data = file_get_contents($abs_url);
//        $res=json_decode($abs_url_data,true);
//        print_r($res);
        $backurl = urldecode(get_cookie('backurl'));
        header("location:index.php?".$backurl);die;
        /*根据用户openid获取用户基本信息*/
    }

    









































    /**
     *                          _ooOoo_
     *                         o8888888o
     *                         88" . "88
     *                         (| -_- |)
     *                          O\ = /O
     *                      ____/`---'\____
     *                    .   ' \\| |// `.
     *                     / \\||| : |||// \
     *                   / _||||| -:- |||||- \
     *                     | | \\\ - /// | |
     *                   | \_| ''\---/'' | |
     *                    \ .-\__ `-` ___/-. /
     *                 ___`. .' /--.--\ `. . __
     *              ."" '< `.___\_<|>_/___.' >'"".
     *             | | : `- \`.;`\ _ /`;.`/ - ` : | |
     *               \ \ `-. \_ __\ /__ _/ .-` / /
     *       ======`-.____`-.___\_____/___.-`____.-'======
     *                          `=---='
     *
     *       .............................................
     *                佛祖保佑             永无BUG
     */
}